package com.dimension.service.impl;

import com.dimension.entity.Image;
import com.dimension.entity.ImageBookmark;
import com.dimension.entity.Tag;
import com.dimension.mapper.ImageBookmarkMapper;
import com.dimension.service.ImageBookmarkService;
import com.dimension.utils.SessionUtil;
import com.dimension.vo.ImageBookmarkList;
import com.dimension.vo.ImageTagBookmark;
import com.dimension.vo.ImageTagHistoryCategory;

import java.util.ArrayList;
import java.util.List;

public class ImageBookmarkServiceImpl implements ImageBookmarkService {
    private ImageBookmarkMapper imageBookmarkMapper = SessionUtil.getMapper(ImageBookmarkMapper.class);

    @Override
    public List<ImageTagBookmark> getUserImageBookmarkList(Integer userId, Integer pageNum, Integer pageSize) {
        List<ImageTagBookmark> imageTagBookmarkList = new ArrayList<>();

        List<ImageBookmarkList> imageBookmarkList = imageBookmarkMapper.getUserImageBookmarkList(userId,pageNum,pageSize);
        for (ImageBookmarkList imageBookmark : imageBookmarkList) {
            Image image = imageBookmark.getImage();
            ImageBookmark imageBookmark1 = imageBookmark.getImageBookmark();

            List<Tag> tagList = imageBookmarkMapper.getTagList(image.getCategoryId());
            ImageTagBookmark imageTagBookmarkList2 = new ImageTagBookmark();
            imageTagBookmarkList2.setImage(image);
            imageTagBookmarkList2.setImageBookmark(imageBookmark1);
            imageTagBookmarkList2.setTagList(tagList);

            imageTagBookmarkList.add(imageTagBookmarkList2);
        }

        return imageTagBookmarkList;
    }

    @Override
    public Integer getCounttotal(Integer userId) {
        Integer total = imageBookmarkMapper.getCounttotal(userId);
        return total;
    }
}
